<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加会员</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/Swiper/3.4.2/js/swiper.jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/Swiper/3.4.2/css/swiper.min.css">
    <script src="${pageContext.request.contextPath}/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/xadmin.js"></script>
</head>
<body>
<!-- 中部开始 -->
<div class="wrapper">
    <!-- 右侧主体开始 -->
    <div class="page-content">
        <div class="content">
            <!-- 右侧内容框架，更改从这里开始 -->
            <form class="layui-form" action="${pageContext.request.contextPath}/admin/addNewMem.action" method="post">
                <div class="layui-form-item">
                    <label for="L_phone" class="layui-form-label">
                        <span class="x-red">*</span>电话
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="L_phone" name="memlogname" required="" lay-verify="phone"
                               autocomplete="off" autofocus class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux" id="spanPhone">
                        <span class="x-red" >*</span>将会成为您唯一的登入名
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_pass" class="layui-form-label">
                        <span class="x-red">*</span>密码
                    </label>
                    <div class="layui-input-inline">
                        <input type="password" id="L_pass" name="mempassword" required="" lay-verify="pass"
                               autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        6到16个字符
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_memrealname" class="layui-form-label">
                        <span class="x-red">*</span>真实名字
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="L_memrealname" name="memrealname" required="" lay-verify="realname"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_sex" class="layui-form-label">
                        <span class="x-red">*</span>性别
                    </label>
                    <div class="layui-input-inline">
                        <input type="radio" id="L_sex" name="memsex" required="" lay-verify="sex" checked
                               autocomplete="off" class="layui-input" value="男" title="男">
                        <input type="radio" id="L_sex2" name="memsex" required="" lay-verify="sex"
                               autocomplete="off" class="layui-input" value="女" title="女">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_email" class="layui-form-label">
                        <span class="x-red">*</span>邮箱
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="L_email" name="mememail" required="" lay-verify="email"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_card" class="layui-form-label">
                        <span class="x-red">*</span>会员卡
                    </label>
                    <div class="layui-input-inline">
                        <select class="layui-input" name="memcard" autocomplete="off" id="L_card">
                            <c:forEach var="card" items="${cardlist}">
                                <option value=${card.cardid}>${card.cardname}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_cardstart" class="layui-form-label">
                        <span class="x-red">*</span>开卡时间
                    </label>
                    <div class="layui-input-inline">
                        <input type="date" id="L_cardstart" name="cardstart" required="" lay-verify="date"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="L_cardend" class="layui-form-label">
                        <span class="x-red">*</span>到期时间
                    </label>
                    <div class="layui-input-inline">
                        <input type="date" id="L_cardend" name="cardend" required="" lay-verify="date"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
<%--                &lt;%&ndash; 根据选择的card设置会员卡开卡时间（当前时间）和到期时间&ndash;%&gt;--%>
<%--                <input type="date" id="cardstart" name="cardstart" hidden>--%>
<%--                <input type="date" id="cardend" name="cardend" hidden>--%>
                <div class="layui-form-item">
                    <label for="L_cardend" class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="add" lay-submit="">
                        添加
                    </button>
                    &nbsp;&nbsp;&nbsp;
                    <button  class="layui-btn" lay-filter="add" lay-submit="" onclick="javascript:x_admin_close();">
                        返回
                    </button>
                </div>
            </form>
            <!-- 右侧内容框架，更改从这里结束 -->
        </div>
    </div>
    <!-- 右侧主体结束 -->
</div>
<!-- 中部结束 -->

<!-- 页面动态效果 -->
<script>
    $("#L_phone").blur(function (){
        //输入框不为空，则进入Ajax判断用户名是否重复
        if ($("#L_phone").val()!= ""){
            //启动Ajax异步判断
            $.ajax({
                url:"${pageContext.request.contextPath}/member/checkName.action",
                type:"post",
                data:{"username":$("#L_phone").val()},
                success:function (msg){
                    // console.log(msg)
                    //接收controller返回数据，no表示重复
                    if (msg.toString()=="no"){
                        layer.msg("号码已被注册，请更换",{icon:1});
                        //注册名重复，则让输入框一直处于焦点获取状态
                        $("#L_phone").focus();
                    }
                },
                error:function () {
                    alert("注册失败！");
                }
            });
        }else{
            //登录名为空，则让输入框一直处于焦点获取状态
            $("#L_phone").focus();
            $("#spanPhone").css("color","red");
            $("#spanPhone").text("登录凭证不能为空");
        }
    });
</script>
</body>
</html>
